﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Web.Models
{
    /// <summary>
    /// 管理后台导航
    /// </summary>
    public class AdminNavigation : Entity
    {
        [Key]
        public int Id { get; set; }

        [Display(Name="视图")]
        [StringLength(50)]
        public string Action { get; set; }

        [Display(Name="控制器")]
        [StringLength(50)]
        public string Controller { get; set; }

        public int? ParentId { get; set; }

        [StringLength(20)]
        public string Icon { get; set; }

        [Display(Name="名称")]
        [StringLength(20)]
        public string Text { get; set; }

        [Display(Name="排序")]
        public int OrderId { get; set; }

        [Display(Name="参数")]
        [StringLength(100)]
        public string Param { get; set; }

        public ICollection<AdminNavigationAuthorization> Authorizations { get; set; }
        public ICollection<AdminPageAuthorization> PageAuthorizations { get; set; }
        public ICollection<AdminPageButton> Buttons { get; set; }
    }

    /// <summary>
    /// 导航权限
    /// </summary>
    public class AdminNavigationAuthorization : Entity
    {
        [Key]
        public int Id { get; set; }

        public int AdminNavigationId { get; set; }
        public virtual AdminNavigation AdminNavigation { get; set; }

        [StringLength(20)]
        public string AuthorizationName { get; set; }

        [StringLength(20)]
        public string AuthorizationNameEn { get; set; }

        [StringLength(100)]
        public string Controller { get; set; }

        [StringLength(100)]
        public string Action { get; set; }
    }

    public class AdminPageAuthorization : Entity
    {
        public int Id { get; set; }

        [ForeignKey("Navigation")]
        public int NavigationId { get; set; }
        public virtual AdminNavigation Navigation { get; set; }

        [ForeignKey("NavigationAuthorization")]
        public int? NavigationAuthorizationId { get; set; }
        public virtual AdminNavigationAuthorization NavigationAuthorization { get; set; }
    }

    /// <summary>
    /// 页面按钮
    /// </summary>
    public class AdminPageButton
    {
        public int Id { get; set; }

        [StringLength(20)]
        public string ButtonText { get; set; }

        [StringLength(20)]
        public string Css { get; set; }

        [StringLength(20)]
        public string Icon { get; set; }

        /// <summary>
        /// 类型,链接或onclick
        /// 0:链接
        /// 1:onclick(ajax)
        /// </summary>
        public int Type { get; set; }

        [StringLength(20)]
        public string Controller { get; set; }

        [StringLength(20)]
        public string Action { get; set; }

        [StringLength(100)]
        public string Param { get; set; }

        [StringLength(100)]
        public string Auth { get; set; }

        [ForeignKey("Navigation")]
        public int NavigationId { get; set; }
        public AdminNavigation Navigation { get; set; }

        public ICollection<AdminPageButtonAuthorization> Authorizations { get; set; }
    }

    public class AdminPageButtonAuthorization
    {
        public int Id { get; set; }

        [ForeignKey("Button")]
        public int ButtonId { get; set; }
        public virtual AdminPageButton Button { get; set; }

        [ForeignKey("NavigationAuthorization")]
        public int? NavigationAuthorizationId { get; set; }
        public virtual AdminNavigationAuthorization NavigationAuthorization { get; set; }
    }
}
